const exec = require('../db/mysql')

const add = (order) => {
  const sql = `insert into sorder(dealer_name,current_sale_out,summation_sale_out,bpcurrent_sale_out,bpsummation_sale_out) values (?,?,?,?,?) ON DUPLICATE KEY UPDATE current_sale_out=values(current_sale_out),summation_sale_out=values(summation_sale_out),bpcurrent_sale_out=values(bpcurrent_sale_out),bpsummation_sale_out=values(bpsummation_sale_out)`
  const params = [order.dealer_name,order.current_sale_out,order.summation_sale_out,order.bpcurrent_sale_out,order.bpsummation_sale_out]
  return exec(sql,params).then(insert=>{
    return insert
  })
}

const list = (params) => {
    const sql = `select * from sorder order by dealer_name `
    return exec(sql,null).then(result=>{
        return result
    })
}

module.exports = {
    add,list
}